//////   Producer.java   //////
import java.io.*;

public class Producer extends Thread {
	public Producer(Cirbuf b) {
		buffer = b;
	}

	public void run() {
		try {
			produce();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	private void produce() throws FileNotFoundException {
		FileInputStream fis = new FileInputStream(new File("data"));
		int c;
		while (true)
			try {
				// if ((c = System.in.read()) >= 0){
				if ((c = fis.read()) >= 0) {
					buffer.put((char) c); // deposit into buffer

				} else {
					buffer.finished(true);
					System.out.println("read  file  done");
					fis.close();
					return; // no more input
				}
			} catch (IOException e) {
				System.err.println(e);
			}

	}

	private Cirbuf buffer; // mutex object
}
